<template>
	<view :data-theme="theme">

		<!-- <view class="picker-view" @click="openAddress">
			<view class="city">
				省市筛选 >
			</view>
		</view> -->
		<!-- <liu-choose-address ref="scroll" :cityArr="cityArr" @change='chooseSuccess'></liu-choose-address> -->

		<view class='sign-record'>
			<view class='list pad30' v-for="(item,index) in signList" :key="index">
				<view class='item'>
					<view class='data'>{{item.month}}</view>
					<view class='listn borRadius14'>
						<view class='itemn acea-row row-between-wrapper' v-for="(itemn,indexn) in item.list" :key="indexn">
							<view>
								<view class='name line1'>{{itemn.title}}</view>
								<view>{{itemn.createDay}}</view>
							</view>
							<view class='num font_color'>+{{itemn.number}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class='loadingicon acea-row row-center-wrapper'>
				<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadtitle}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSignMonthList,
		getCityList
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	let app = getApp();
	export default {
		data() {
			return {
				loading: false,
				loadend: false,
				loadtitle: '加载更多',
				page: 1,
				limit: 8,
				signList: [],
				theme: app.globalData.theme,
				cityArr: []
			};
		},
		computed: mapGetters(['isLogin']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.getSignMoneList();
					}
				},
				deep: true
			}
		},
		onLoad() {
			if (this.isLogin) {
				this.getSignMoneList();
				this.getCityList()
			} else {
				toLogin();
			}
		},
		onReachBottom: function() {
			this.getSignMoneList();
		},
		methods: {
			//打开地址选择器
			openAddress() {
				this.$refs.scroll.open()
			},
			//地址选择成功
			chooseSuccess(e) {
				console.log('所选择的地址信息:', e)




			},
			getCityList() {
				let params = {
					parentId: 0
				}
				getCityList(params).then(res => {
					console.log(res)
					this.cityArr = res.data.list
				})
			},


			/**
			 * 获取签到记录列表
			 */
			getSignMoneList: function() {
				let that = this;
				if (that.loading) return;
				if (that.loadend) return;
				that.loading = true;
				that.loadtitle = "";
				getSignMonthList({
					page: that.page,
					limit: that.limit
				}).then(res => {
					let list = res.data.list;
					let loadend = list.length < that.limit;
					that.signList = that.$util.SplitArray(list, that.signList);
					that.$set(that, 'signList', that.signList);
					that.loadend = loadend;
					that.loading = false;
					that.loadtitle = loadend ? "哼😕~我也是有底线的~" : "加载更多"
				}).catch(err => {
					that.loading = false;
					that.loadtitle = '加载更多';
				});
			},
		}
	}
</script>

<style lang="scss">
	.font_color {
		@include main_color(theme);
	}

	.picker-view {
		background-color: white;

		.city {
			display: inline-block;
			// width: 50%;
			// text-align: center;
			padding: 20rpx;
			padding-left: 40rpx;
			font-size: 24rpx;
		}
	}
</style>